import machine,time,network
from machine import Pin,I2c,PWM
import bluetooth
import ahtx0 

ble = bluetooth.BLE()
i2c=I2c(0,scl=Pin(9),sda=Pin(8),freq=400000)
sensor = ahtx0.AHT20(i2c)
led_R=PWM(Pin(4))
led_G=PWM(Pin(3))
led_B=PWM(Pin(2))

led_R.freq(1000)
led_G.freq(1000)
led_B.freq(1000)

led_R.duty(0)
led_G.duty(0)
led_B.duty(0)

ap = network.WLAN(network.AP_IF)  # AP_IF 表示接入点模式
ap.active(True)  # 激活接入点
ssid = "HS_LED"
ap.config(essid=ssid, authmode=network.AUTH_OPEN)
for i in range(0, 1000, 100):
    led_B.duty(1023)
    time.sleep_ms(1)
print('wifi ready', ap.ifconfig()[0])

def get_temperature():
    temperature = sensor.temperature
    humidity = sensor.relative_humidity
    print("Temperature: {:.2f}°C, Humidity: {:.2f}%".format(temperature, humidity))
    return temperature, humidity

def water_link():
    for i in range(0, 1000, 10):
        led_R.duty(i)
        led_G.duty(i)
        led_B.duty(i)
        time.sleep_ms(10)

def sun_light():
    for i in range(0,1024,100):
        led_R.duty(i)
        time.sleep_ms(1)
    for i in range(0,520,100):
        led_G.duty(i)
        time.sleep_ms(1)


 